package com.zc.hadoop.lzmh.log;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

/**
 * 调用日志信息统计Writable
 *
 */
public class LogWritable implements WritableComparable<LogWritable> {

	// 值
	private int timeValue;
	// 数量
	private int count;

	// 只要数据在网络中传输，就要用到序列化和反序列化

	// 先数据序列化，把对象（字段）写到字节输出流中
	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(timeValue);
		out.writeInt(count);
	}

	// 数据反序列话,把对象从字节输出流中读取出来，并且序列化和反序列化的字段顺序要相同
	@Override
	public void readFields(DataInput in) throws IOException {
		this.timeValue = in.readInt();
		this.count = in.readInt();

	}

	/**
	 * 比较
	 */
	@Override
	public int compareTo(LogWritable o) {
		int thisValue = this.timeValue;
	    int thatValue = o.timeValue;
	    return (thisValue<=thatValue ? -1 : 1);
	}

	@Override
	public String toString() {
		return "LogWritable [timeValue=" + timeValue + ", count=" + count + "]";
	}

	// 构造函数（空参）
	public LogWritable() {
		super();
	}

	// 构造函数
	public LogWritable(int timeValue, int count) {
		super();
		this.timeValue = timeValue;
		this.count = count;
	}
	
	// get,set

	public int getTimeValue() {
		return timeValue;
	}

	public void setTimeValue(int timeValue) {
		this.timeValue = timeValue;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

}
